import os
import numpy as np
import win32com.client as win32 
import sys

with open('input.txt', 'r') as F:
    l1=float(F.readline().strip())  #condenser T 25-35
    l2=float(F.readline().strip())  # 1.5-4
    l3=float(F.readline().strip())  # 8-16
    l4=float(F.readline().strip())  # 0.5-6
    l5=float(F.readline().strip())  # 0.5-6
    l6=float(F.readline().strip())  # 0.1-1
    l7=float(F.readline().strip())  # 0.1-1

aspen = win32.Dispatch('Apwn.Document')

aspen.InitFromArchive2(os.path.abspath('Euc.bkp'))

aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_TEMPVAL\O-2\#1").Value= l1   #25
aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_DURATION\O-2").Value= l2     #3.5 
aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_DURATION\O-3").Value= l3    #9.5
aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_VALUE\O-2\#0").Value= l4    #2
aspen.Tree.FindNode("\Data\Blocks\B1\Input\OPS_VALUE\O-3\#1").Value= l5    #2
aspen.Tree.FindNode("\Data\Blocks\B1\Input\JH_DUTY").Value=l6
aspen.Tree.FindNode("\Data\Blocks\B1\Input\COND_PRES").Value=l7
aspen.Engine.Run2()
S2=aspen.Tree.FindNode("\Data\Streams\S2\Output\MASSFLMX\MIXED").Value
S3=aspen.Tree.FindNode("\Data\Streams\S3\Output\MASSFLMX\MIXED").Value
#C1=aspen.Tree.FindNode("\Data\Streams\S2\Output\MASSFRAC\MIXED\TARGET").Value  
C1= aspen.Tree.FindNode("\Data\Streams\S2\Output\MASSFRAC\MIXED\TARGET").Value      
C3= aspen.Tree.FindNode("\Data\Streams\S3\Output\TEMP_OUT\MIXED").Value   #T <150 
c1=0.775-C1
c3=C3-150
Obj= (l6*0.1192*(l2+l3+0.5))*10
with open("output.txt", "w") as file:
  file.write(f"{Obj} {c1} {c3} ")
with open("ObJ.txt", "w") as O:
   O.write(f"{Obj} ")

#print(Obj)
#file = open("output.txt")
#print(file.read())
  # lines = [f"{Obj:1.8f}\n", f"{c1:1.8f}\n", f"{c2:1.8f}"]#,f"{c3:1.8f}" ]
  # lines = [f"{Obj:1.8f}\n"]#, f"{c3:1.8f}" ]
  # file.writelines(lines)
sys.exit(0)